<template>
  <div class="binding-family-main base-main">
    <van-swipe-cell v-for="(item, index) in dataList" :key="index"  >
      <div class="content bgcFFF pdlr15 color45454D fs14">
        <span>{{item.name}}</span>
        <span class="phone">{{item.phone}}</span>
      </div>
      <template #right>
        <van-button square text="删除" type="danger" class="delete-button" @click="delFamily(item)"/>
      </template>
    </van-swipe-cell>

    <div class="btn-box bgcFFF fixed">
      <span class="base-btn" @click="addFamily">+ 添加家人</span>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import { Toast, Dialog } from 'vant'
  export default {
    data() {
      return {
        dataList: []
      }
    },
    created() {
      this.getData()
    },
    methods: {
      getData() {
//        this.$ajax({
//          url: '/getFamilyData',
//          method: 'get'
//        }).then(res => {
//          this.dataList = res.data.data
//        })
      },
      // 删除
      delFamily(item) {
//        console.log(item);
        const _this = this
        Dialog.confirm({
          message: '确定删除吗？',
        }).then(() => {
//          _this.$ajax({
//            url: '/delFamily',
//            method: 'post'
//          }, {
//            id: item.id
//          }).then(res => {
//            Toast('删除成功')
//            let arr = []
//            this.dataList.map(obj => {
//              if(item.id != obj.id) {
//                arr.push(obj)
//              }
//            })
//            this.dataList = arr
//          })
        }).catch(() => {
        })
      },
      // 添加
      addFamily() {
        this.$router.push({
          name: 'addFamily'
        })
      },
    },
  }
</script>

<style lang="scss">
@import "../../assets/css/healthMonitoring/bindingFamily";
</style>
